/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facades;

import entities.D;
import entities.Iva;
import entities.Pais;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author damfercer
 */
@Stateless
public class IvaFacade extends AbstractFacade<Iva> {
    @PersistenceContext(unitName = "CorporatePU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public IvaFacade() {
        super(Iva.class);
    }
    
    public Iva getIvaDePaisYCategoria(Pais p, D categoria){
        Iva iva=null;
        Query q=em.createNamedQuery("Iva.findByPaisYD", Iva.class);
        q.setParameter("idPais", p.getIdPais());
        q.setParameter("idD", categoria.getIdD());
        List<Iva> resultados=q.getResultList();
        if(resultados!=null && !resultados.isEmpty()){
            iva=resultados.get(0);
        }
        return iva;
    }
    
}
